/**
 * Created by AndrewH on 2017/9/7.
 */

/**
 *
 * @type {{addCookie: cookieUtil.addCookie,   添加设置cookie
 *         getCookieValue: cookieUtil.getCookieValue,  获取cookie的值，根据cookie的键获取值
 *         deleteCookie: cookieUtil.deleteCookie  根据cookie的键，删除cookie
 *         }}
 */
var cookieUtil = {
    addCookie : function(name,value,days,path){
        var name=encodeURIComponent(name);
        var value=value;
        if(name=='password'){
            value=value;
        }else{
            value=encodeURIComponent(value);
        }

        var expires = new Date();
        expires.setTime(expires.getTime() + days * 3600000 * 24);
        path = path == "" ? "" : ";path=" + path;
        var _expires = (typeof days) == "string" ? "" : ";expires=" + expires.toUTCString();
        document.cookie = name + "=" + value + _expires + path;
    },
    getCookieValue : function(name){
        var allcookies = document.cookie;
        name += "=";
        var pos = allcookies.indexOf(name);
        if (pos != -1){
            var start = pos + name.length;
            var end = allcookies.indexOf(";",start);
            if (end == -1) end = allcookies.length;
            var value = allcookies.substring(start,end);
            return (value);
        }else{  //搜索失败，返回空字符串
            return "";
        }
    },
    deleteCookie : function(name,path){
        var expires = new Date(0);
        path = path == "" ? "" : ";path=" + path;
        document.cookie = name + "="+ ";expires=" + expires.toUTCString() + path;
    }

};

//全屏
var fullscreen = function () {
    elem = document.body;
    if (elem.webkitRequestFullScreen) {
        elem.webkitRequestFullScreen();
    } else if (elem.mozRequestFullScreen) {
        elem.mozRequestFullScreen();
    } else if (elem.requestFullScreen) {
        elem.requestFullscreen();
    } else {
        //浏览器不支持全屏API或已被禁用
    }
};

